package cn.my.framework.common.repo;

import cn.my.framework.common.entity.Permission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * Created by zhangl_lc on 2017/7/6.
 */
public interface PermissionRepo extends JpaRepository<Permission,Integer> {

    @Query(value = "select distinct p.* from permission p inner join role_perm rp on rp.perm_code = p.code where rp.role_code = :roleCode",nativeQuery = true)
    List<Permission> selectByRoleCode(@Param("roleCode") String roleCode);

    @Query(value = "select distinct p.* from permission p inner join role_perm rp on rp.perm_code = p.code inner join user_role ur on ur.role_code = rp.role_code where ur.user_code = :userCode",nativeQuery = true)
    List<Permission> selectByUserCode(@Param("userCode") String userCode);
}
